layui.use(['layer','rate','table','jquery','form'],function(){
    let layer = layui.layer,
        table = layui.table,
        $ = layui.jquery,
        rate = layui.rate,
        form = layui.form;

    //加载数据表格
    let tabInstance = table.render({
        elem: '#archiveService',
        url: '/service-user-allot/archiveService', //数据接口
        page: true, //开启分页
        limit:5, //每页显示的条数，默认10
        limits:[5,10,15,20,], //每页显示条数选择框数据
        request:{
            pageName: 'current',
            limitName: 'size'
        },
        cols: [[ //表头
            {field: 'serviceId', title: '编号', width:80, sort: true, fixed: 'left'},
            {field: 'customerName', title: '客户名称'},
            {field: 'outline', title: '概要'},
            {field: 'serviceType', title: '服务类型'},
            {field: 'creationName', title: '创建人'},
            {field: 'creationTime', title: '创建时间'},
            {field: 'status', title: '状态'},
            {title: '操作', width: 100,fixed:'right',toolbar:"#archiveTool"}
        ]]
    });

    //搜索监听启用
    form.on('submit(search)',function(data){
        tabInstance.reload({
            where :data.field
        });
        return false;
    });

    //工具栏操作
    table.on('tool(archiveService)',function(obj){
        switch (obj.event){
            case 'archive_btn':
                let s =layer.open({
                    title:"服务反馈",
                    type:2,
                    content:"views/service_management/archive.jsp",
                    area:['50%','70%'],
                    offset:'t',
                    skin:"layui-layer-molv",
                    btn:['关闭'],

                    //弹出层成功后执行的回调函数
                    success: function(layero, index){
                        let body = layer.getChildFrame("body",index);
                        let  id = body.find("#love");
                       rate.render({
                            elem: id,
                            length: 5,
                            value: obj.data.satisfaction,
                            theme: '#FFB800',
                            text: true,
                            readonly: true,
                            setText: function (value) {
                                var arrs = {
                                    '1': '极差'
                                    , '2': '差'
                                    , '3': '中等'
                                    , '4': '好'
                                    , '5': '非常好'
                                };
                                this.span.text(arrs[value]);
                            }
                        });
                        // rate.render();
                        body.find(".num").val(obj.data.serviceId);
                        body.find(".customerName").val(obj.data.customerName);
                        body.find(".outline").val(obj.data.outline);
                        body.find(".serviceType").val(obj.data.serviceType);
                        body.find(".creationName").val(obj.data.creationName);
                        body.find(".creationTime").val(obj.data.creationTime);
                        body.find(".serviceReq").val(obj.data.serviceReq);
                        body.find(".userName").val(obj.data.userName);
                        body.find(".status").val(obj.data.status);
                        body.find(".allotTime").val(obj.data.allotTime);
                        body.find(".handleTime").val(obj.data.handleTime);
                        body.find(".handleName").val(obj.data.handleName);
                        body.find(".serviceHandle").val(obj.data.serviceHandle);
                        body.find(".handleResult").val(obj.data.handleResult);
                    },
                    yes: function(index, layero){
                        layer.close(index);
                            // setTimeout(function(){
                            //     layer.close(index);
                            //     // parent.location.reload();
                            // },1000);
                    }
                });

                break;
        }
    });

});

